
import requests
import json
import datetime


class PublishArticleAutomatic():
    """初始化"""
    def __init__(self,login_info={},email_config={},accounts=[],):
        self.login_info = login_info
        self.email_config = email_config
        self.accounts = accounts
        timestamp = datetime.datetime.now().timestamp()
        millis_timestamp = int(timestamp * 1000)
        # 末尾的3位改成0
        millis_timestamp2 = millis_timestamp - millis_timestamp % 1000
        self.common_headers ={
            "accept": "application/json, text/plain, */*",
            "accept-language": "zh-CN",
            "accept-encoding": "gzip, deflate, br",
            "content-type": "application/json",
            "cookie":"wx_qtype3_1=314267141;__tenant=3a09a466-e15f-6885-4679-765edd91824c;SERVERID=42112eb2fea97c46b25b6b3298b85dbe|1697337088|1697334660",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "cross-site",
            "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.146 Safari/537.36",
            "ssounique":str(millis_timestamp),
            "unique":str(millis_timestamp2),
        }
        self.accessToken=""
        self.encryptedAccessToken=""
        self.expireInSeconds=""
        self.userId=""
        self.tenantId=""
        
    """登录"""
    def login(self):
        url = "https://api-v2.yixiaoer.cn/api/passport/login"
        data = {
                "phoneNumber:": self.login_info['phoneNumber'],
                "password": self.login_info['password'],
            }
        print("登录信息",data)
        headers= self.common_headers
        res = requests.post(url, headers=headers,data=data)
        res = json.loads(res.text)
        print("登录结果",res)
    
    """获取多媒体账号列表"""
    def get_accounts(self):
        url = "https://api-v2.yixiaoer.cn/api/account-center/newpage【"
        headers= self.common_headers
        res = requests.get(url, headers=headers)
        res = json.loads(res.text)
        print(res)
    
    """文章推送到线上"""
    def publish_articles(self):
        url = "https://api-v2.yixiaoer.cn/api/article/push-v2"
        headers= self.common_headers
        res = requests.post(url, headers=headers)
        res = json.loads(res.text)
        print(res)
    
    """获取发布的结果"""
    def get_publish_result(self):
        url = "https://api-v2.yixiaoer.cn/api/task/callback/mediacontent"
        headers= self.common_headers
        res = requests.get(url, headers=headers)
        res = json.loads(res.text)
        print(res)
        


login_info={"phoneNumber":"13397642288","password":"0000000s"}
test = PublishArticleAutomatic(login_info=login_info)
test.login()